<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      .TI {
        display: flex;
      }
    </style>
  </head>
  <body>
    <div id="app">
      <div class="TI">
        <div v-for="(inex,id) in xihuan">
          <input type="checkbox" @click="txt(id)" />
          {{inex}}
        </div>
      </div>
      <div><p v-for="(inex) in zhanshi">{{inex}}</p></div>
    </div>
    <script src="../vue.js"></script>
    <script>
      const app = new Vue({
        el: "#app",
        //定义属性
        data: {
          xihuan: [
            "科幻",
            "喜剧",
            "动漫",
            "冒险",
            "科技",
            "军事",
            "娱乐",
            "奇闻",
          ],
          zhanshi: [],
        },
        //定义方法
        methods: {
          txt(id) {
            if (this.zhanshi.includes(this.xihuan[id])) {
              this.zhanshi = this.zhanshi.filter(
                (inex) => inex !== this.xihuan[id]
              );
              return;
            }
            this.zhanshi.push(this.xihuan[id]);
          },
        },
      });
    </script>
  </body>
</html>
